#!/bin/bash

root="."
pythonI="./venv/bin/python3"

export PYTHONPATH=$(readlink -f "$root/src/trace_reconstructor/ports/python"):$PYTHONPATH

run_python_script() {
  $pythonI "$root/src/trace_reconstructor/ports/python/executor.py" \
    --relative_path "$1" \
    --compressed "$2" \
    --cache_rate "$3" \
    --fix "$4" \
    --test_name "$5" \
    --load_level "$6" \
    --compress_factor "$7" \
    --repeat_factor "$8" \
    --execute_parallel "$9" \
    --results_directory "${10}" \
    --clear_cache "${11}" \
    --predictor_indices "${12}" &
}

clear_cache="0"
test_name_suffix="test"
results_directory=$(pwd)/results/$(date +%Y-%m-%d_%H-%M-%S)/
#rm -rf $results_directory
mkdir -p $results_directory

# Predictor options
# ("MaxScoreBatch", TraceWeaverV2(all_spans, all_processes))
# ("MaxScoreBatchParallel", TraceWeaverV2(all_spans, all_processes))
# ("MaxScore", TraceWeaverV1(all_spans, all_processes))
# ("WAP5", WAP5(all_spans, all_processes))
# ("FCFS", FCFS(all_spans, all_processes))
# ("ArrivalOrder", ArrivalOrder(all_spans, all_processes))
# ("vPathOld", vPathOld(all_spans, all_processes))
# ("vPath", vPath(all_spans, all_processes))
# ("MaxScoreBatchParallelWithoutIterations", TraceWeaverV3(all_spans, all_processes))
# ("MaxScoreBatchParallel", TraceWeaverV3(all_spans, all_processes))
# ("MaxScoreBatchSubsetWithSkips", TraceWeaverV3(all_spans, all_processes))

predictor_indices="3,4,7,10"

tests=(
  "data/otel_demo/otel_load1 0 0 7 otel_demo_test 1 1 1 0 $results_directory $clear_cache $predictor_indices"
)

for test in "${tests[@]}"; do
  params=($test)
  run_python_script "${params[0]}" "${params[1]}" "${params[2]}" "${params[3]}" "${params[4]}" "${params[5]}" "${params[6]}" "${params[7]}" "${params[8]}" "${params[9]}" "${params[10]}" "${params[11]}"
done

wait

echo "All tests have concluded."

load_levels="1"
app_names="otel_demo"
output_file_name_1="$results_directory/fig4a.pdf"
$pythonI "$root/utils/plot_accuracy_vs_load_multiple_apps.py" $results_directory $test_name_suffix $output_file_name_1 $load_levels $app_names

output_file_name_2="$results_directory/fig4b.pdf"
$pythonI "$root/utils/plot_accuracy_vs_response_times_multiple_apps.py" $results_directory $test_name_suffix $output_file_name_2 $load_levels $app_names

rmdir --ignore-fail-on-non-empty $results_directory
